package net.zoneland.zrdp.biz.controller.uniflow;



import net.zoneland.zrdp.biz.common.Constants;
import net.zoneland.zrdp.biz.domain.FlowMainInfo;
import net.zoneland.zrdp.biz.domain.pojo.query.TaskQuery;
import net.zoneland.zrdp.biz.domain.pojo.vo.TaskAndReadCount;
import net.zoneland.zrdp.biz.service.IFlowMainInfoService;
import net.zoneland.zrdp.biz.service.IWorkOrderService;
import net.zoneland.zrdp.common.core.controller.BaseController;
import net.zoneland.zrdp.common.core.domain.AjaxResult;
import net.zoneland.zrdp.common.core.page.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 工单任务查询列表.
 *
 */
@RestController
@RequestMapping("/biz/workOrder")
public class WorkOrderController extends BaseController {

    @Resource
    private IWorkOrderService workOrderService;

    @Resource
    private IFlowMainInfoService flowMainInfoService;

    /**
     * 综合查询
     */

    @PreAuthorize("@ss.hasPermi('workOrder:integratedQuery')")
    @GetMapping("/listFlowMainInfo")
    public TableDataInfo listFlowMainInfo(final FlowMainInfo flowMainInfo) {
        startPage();
        final List<FlowMainInfo> list = flowMainInfoService.integratedQuery(flowMainInfo);
        return getDataTable(list);
    }

    /**
     * 待办列表.
     * @param tableForm 任务查询表单.
     * @return 分页待办列表信息
     **/

    @GetMapping("/getTaskList")
    @PreAuthorize("@ss.hasPermi('workOrder:getTaskList')")
    public TableDataInfo getTaskList(final TaskQuery tableForm) {
        tableForm.setStates(Constants.READY_ASSIGNED_STATES);
        tableForm.setOwner(getUsername());
        return getDataTable(workOrderService.queryTask(tableForm, false));
    }

    /**
     * 获取流程信息.
     * @return 所有流程信息
     **/

    @GetMapping("/getFlowInfo")
    public AjaxResult getFlowInfo() {
        return success(workOrderService.getFlowInfo());
    }

    /**
     * 获取流程状态.
     * @return 所有流程状态
     **/

    @GetMapping("/getFlowState")
    public AjaxResult getFlowState() {
        return success(workOrderService.getFlowState());
    }

    /**
     * 获取待办、待阅数量信息.
     * @return 待办、待阅数量信息
     **/

    @GetMapping("/getTaskAndReadCount")
    public AjaxResult getTaskAndReadCount() {
        final TaskAndReadCount taskAndReadCount = new TaskAndReadCount();
        final String username = getUsername();
        taskAndReadCount.setTaskCount(workOrderService.getTaskCount(username));
        taskAndReadCount.setReadCount(workOrderService.getReadCount(username));
        return success(taskAndReadCount);
    }

    /**
     * 已办列表.
     * @param tableForm 任务查询表单.
     * @return 分页已办列表信息
     **/

    @GetMapping("/getDoneList")
    @PreAuthorize("@ss.hasPermi('workOrder:getDoneList')")
    public TableDataInfo getDoneList(final TaskQuery tableForm) {
        tableForm.setStates(Constants.FINISH_STOP_SINGLE_ASSIGNMENT_STATES);
        tableForm.setOwner(getUsername());
        return getDataTable(workOrderService.queryTaskWithCurrentNodeName(tableForm, true));
    }



    /**
     * 待阅列表.
     * @param tableForm 任务查询表单.
     * @return 分页待阅列表
     **/

    @GetMapping("/getReadList")
    @PreAuthorize("@ss.hasPermi('workOrder:getReadList')")
    public TableDataInfo getReadList(final TaskQuery tableForm) {
        tableForm.setStates(Constants.READY_ASSIGNED_STATES);
        tableForm.setOwner(getUsername());
        return getDataTable(workOrderService.queryRead(tableForm));
    }



    /**
     * 已阅列表.
     * @param tableForm 任务查询表单.
     * @return 分页已阅列表
     **/

    @GetMapping("/getReadDoneList")
    @PreAuthorize("@ss.hasPermi('workOrder:getReadDoneList')")
    public TableDataInfo getReadDoneList(final TaskQuery tableForm) {
        tableForm.setStates(Constants.FINISH_STOP_SINGLE_ASSIGNMENT_STATES);
        tableForm.setOwner(getUsername());
        return getDataTable(workOrderService.queryRead(tableForm));
    }



    /**
     * 我的草稿列表.
     * @param tableForm 任务查询表单.
     * @return 分页草稿列表
     **/

    @GetMapping("/getDraftList")
    @PreAuthorize("@ss.hasPermi('workOrder:getDraftList')")
    public TableDataInfo getDraftList(final TaskQuery tableForm) {
        tableForm.setStates(Constants.DRAFT_STATES);
        tableForm.setOwner(getUsername());
        return getDataTable(workOrderService.queryTask(tableForm, false));
    }



    /**
     * 我的申请列表.
     * @param tableForm 任务查询表单.
     * @return 分页分页申请列表
     **/

    @GetMapping("/getApplyList")
    @PreAuthorize("@ss.hasPermi('workOrder:getApplyList')")
    public TableDataInfo getApplyList(final TaskQuery tableForm) {
        tableForm.setStates(Constants.READY_FINISH_DRAFT_ASSIGNED_STATES);
        final String userId = getUsername();
        tableForm.setApplicant(userId);
        tableForm.setOwner(userId);
        return getDataTable(workOrderService.queryTaskWithCurrentNodeName(tableForm, true));
    }



}
